package com.example.data.serviceImpl;

import com.example.data.dao.DataDicDAO;
import com.example.data.entity.DataDic;
import com.example.data.service.DataDicService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/*pagehelper 分页逻辑必须在service层*/

@Service("DataDicServiceImpl")
public class DataDicServiceImpl implements DataDicService {

    @Autowired
    DataDicDAO dataDicDAO;

    //条件查询
    @Override
    @Transactional
    public PageInfo<DataDic> queryData(DataDic dataDic,int pageNum, int pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<DataDic> list = dataDicDAO.queryData(dataDic);
        PageInfo<DataDic> dataList  =  new PageInfo<DataDic>(list);
        return dataList;
    }

    //查询全部
    @Override
    @Transactional
    public PageInfo<DataDic> queryDataAll(int pageNum,int pageSize) {

        PageHelper.startPage(pageNum,pageSize);
        List<DataDic> list = dataDicDAO.queryDataAll();
        PageInfo<DataDic> dataList  =  new PageInfo<DataDic>(list);
        return dataList;
    }

    @Override
    @Transactional
    public void saveData(DataDic dataDic) {
        dataDicDAO.savaData(dataDic);
    }

    @Override
    @Transactional
    public void modify(DataDic dataDic) {
        dataDicDAO.modify(dataDic);
    }

    @Override
    @Transactional
    public void delete(DataDic dataDic) {
        dataDicDAO.delete(dataDic);
    }
}
